<!-- 提示弹窗 -->
<template>
	<view class='cu-modal' :class='{show: show}'>
		<view class='modal'>
			<view class="head">
				{{title}}
				<image @click="close" class="head-close"
					src="https://ballon-vdigit.oss-cn-qingdao.aliyuncs.com/20250228/202502281528108113.png" mode="">
				</image>
			</view>
			<view class="list">
				<scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="getMore">
					<view v-for="(item,index) in list" :key="index" class="item">
						<view class="item-head">
							<view class="item-head-text">{{item.cargoName}}</view>
							<view class="item-head-id">ID:{{item.cargoNo}}</view>
						</view>
						<view v-for="(remind,remindIndex) in item.options" :key="remindIndex" class="item-content">
							<view class="item-content-text">
								{{remind.content}}
							</view>
							<view class="item-bot">
								<view class="item-time">
									提醒时间：{{remind.time}}
								</view>
								<view @click="delItem(remind)" class="item-del">
									删除
								</view>
							</view>
							
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<showModal1 ref="showModal1"></showModal1>
	</view>
</template>

<script>
	import {
		pageRemind,
		listRemind,
		delRemind
	} from "@/api/pet/remind/saler.js"
	import showModal1 from "@/components/show-modal1.vue"
	export default {
		props: {
			all: {
				type: [Boolean, String],
				default: false
			}
		},
		components:{
			showModal1
		},
		data() {
			return {
				show: false,
				title: '',
				row: {},
				petTeam: {},
				type: '',
				list: [],
				total: 0,
			}
		},
		created() {
			this.petTeam = uni.getStorageSync('pet_team')
		},
		methods: {
			handleOpen(params) {
				if (params) {
					this.type = params.type
					this.row = params.item || {}
					this.title = params.title || ''
				}
				this.getList()
				this.show = true;
			},
			delItem(item){
				this.$refs.showModal1.open({
					content:'确认要删除吗？',
					success:()=>{
						delRemind(item.id).then(res=>{
							uni.showToast({
								title:'操作成功',
								icon:'none'
							})
							this.getList()
						})
					}
				})
				
			},
			getList() {
				uni.showLoading({
					mask: true
				})
				listRemind({
					// ...this.params,
					teamId: this.type == 'SALER' ? this.petTeam.teamId : undefined,
					cargoId: !this.all ? this.row.id : undefined
				}).then(res => {
					let list = []
					for (let i = 0; i < res.length; i++) {
						let index = list.findIndex(item=>item.cargoId == res[i].cargoId)
						if(index>=0){
							list[index].options.push({
								id:res[i].id,
								content:res[i].content,
								time:res[i].time,
							})
						}else{
							list.push({
								cargoName:res[i].cargoName,
								cargoId:res[i].cargoId,
								options:[{
									id:res[i].id,
									content:res[i].content,
									time:res[i].time,
								}],
							})
						}
					}
					this.list = list
					uni.hideLoading()
				})
			},
			changeDate(e) {

			},
			close() {
				this.show = false;
			},
		}
	}
</script>

<style scoped lang="scss">
	.modal {
		width: 100%;
		position: absolute;
		left: 0;
		bottom: 0;
		background: #F8F8F8;
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		padding-bottom: 92rpx;
		z-index: 1024;

		.head {
			width: 100%;
			text-align: center;
			position: relative;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			color: #222222;
			line-height: 42rpx;
			margin: 32rpx 0 40rpx;

			.head-close {
				width: 40rpx;
				height: 40rpx;
				position: absolute;
				top: 50%;
				right: 32rpx;
				transform: translateY(-50%);
			}
		}

		.list {
			padding: 0 16rpx;
			overflow: auto;
			// max-height: 50vh;

			.scroll-Y {
				height: 50vh;
				.item {
					width: 100%;
					padding: 24rpx;
					background: #fff;
					border-radius: 16rpx;
					margin-bottom: 24rpx;

					&:last-child {
						margin-bottom: 0;
					}

					.item-head {
						width: 100%;
						display: flex;
						align-items: center;
						margin-bottom: 12rpx;
						overflow: hidden;

						.item-head-text {

							// max-width: max-content;
							white-space: nowrap;
							overflow: auto;
							font-family: PingFangSC, PingFang SC;
							font-weight: 600;
							font-size: 36rpx;
							color: #222222;
							line-height: 50rpx;
							text-align: left;
						}

						.item-head-id {
							margin-left: 12rpx;
							white-space: nowrap;
							padding: 0 12rpx;
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							font-size: 22rpx;
							color: #222222;
							line-height: 36rpx;
							background: #FFF6CD;
							border-radius: 29rpx;
						}
					}

					.item-content {
						margin-bottom: 22rpx;
						border-bottom: 1rpx dashed #E5E5E5;
						padding-bottom: 24rpx;

						&:last-child {
							margin-bottom: 0;
							border-bottom: none;
							padding-bottom: 0;
						}

						.item-content-text {
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							font-size: 28rpx;
							color: #222222;
							line-height: 40rpx;
							text-align: justify;
						}
						.item-bot{
							display: flex;
							align-items: center;
							justify-content: space-between;
							margin-top: 12rpx;
							.item-time {
								font-family: PingFangSC, PingFang SC;
								font-weight: 400;
								font-size: 24rpx;
								color: #999999;
								line-height: 33rpx;
								text-align: left;
							}
							.item-del{
								font-family: PingFangSC, PingFang SC;
								font-weight: 400;
								font-size: 24rpx;
								color: red;
								line-height: 33rpx;
							}
						}
						
					}

				}
			}
		}
	}
</style>